Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Transaction Watcher #386

Merged
merged 6 commits into from
Feb 21, 2024
Merged

Refactor Transaction Watcher #386

merged 6 commits into from
Feb 21, 2024

Conversation

popenta
Copy link
Contributor

@popenta popenta commented Feb 20, 2024

Later edit: the breaking part was recovered in #404.

This PR introduces breaking changes.

Before, the methods in the TransactionWatcher class required an input parameter of type ITransaction. Now, in order to be compatible with the TransactionNext class, the methods simply require the transaction hash.

Migrated from:

public async awaitCompleted(transaction: ITransaction): Promise<ITransactionOnNetwork> {...}

to:

public async awaitCompleted(txHash: string): Promise<ITransactionOnNetwork> {...}

@popenta popenta self-assigned this Feb 20, 2024
@andreibancioiu andreibancioiu self-requested a review February 20, 2024 16:34
Copy link
Contributor

@andreibancioiu andreibancioiu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 🚀

We should also add the prefix "Breaking change" in the PR title, even if the note exists already in the description.

@@ -24,6 +24,7 @@ interface TokenComputer {
/**
* Use this class to create transactions for native token transfers (EGLD) or custom tokens transfers (ESDT/NTF/MetaESDT).
*/
// this name is only temporary; the class will be renamed to `TransferTransactionsFactory`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adjust comment, to be inside the one above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved it.

@@ -61,7 +61,7 @@ export class TransactionNextBuilder {
gasLimit: gasLimit,
value: this.amount || 0n,
data: data.valueOf(),
chainID: this.config.toString(),
chainID: this.config.chainID,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -28,6 +28,7 @@ describe("test delegation transactions factory", function () {
assert.deepEqual(transaction.data, Buffer.from("createNewDelegationContract@010f0cf064dd59200000@0a"));
assert.equal(transaction.gasLimit, 60126500n);
assert.equal(transaction.value, value);
assert.equal(transaction.chainID, config.chainID);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -58,8 +58,8 @@ describe("fetch transactions from local testnet", function () {
await provider.sendTransaction(transactionDeploy);
await provider.sendTransaction(transactionIncrement);

await watcher.awaitCompleted(transactionDeploy);
await watcher.awaitCompleted(transactionIncrement);
await watcher.awaitCompleted(transactionDeploy.getHash().hex());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a future PR, we should also adjust the integration tests to use the transaction factories for deploy, call etc.

it("should create transaction using the NextTokenTransferFactory", async function () {
this.timeout(70000);

let provider = createLocalnetProvider();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here & below, use const when applicable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@@ -325,4 +330,51 @@ describe("test on local testnet", function () {
queryResponse = await provider.queryContract(query);
assert.equal(decodeUnsignedNumber(queryResponse.getReturnDataParts()[0]), 0);
});

it("counter: should deploy and call using the SmartContractFactory", async function () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 👍 (in relation to the other comment about a next PR for integration tests, only now I see this test)

await alice.sync(provider);

const transactionComputer = new TransactionComputer();
const config = new TransactionsFactoryConfig(network.ChainID);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I see - we should pass init parameters to TransactionsFactoryConfig as options (even if now there's only one, the chain ID) - similar to SmartContractTransactionsFactory etc. This, in order to avoid breaking changes in the future, if the config should be extended to receive an extra parameter in the constructor.

This would be for another, separate PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do in the next PR.

bytecode: bytecode,
gasLimit: 3000000n,
});
deployTransaction.nonce = BigInt(alice.account.nonce.valueOf());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit verbose, but good at this moment. In the cookbook I think we will not mention AccountNonce class anymore - left for the client code to hold & handle the nonce.

@popenta popenta changed the title Refactor Transaction Watcher Breaking Change: Refactor Transaction Watcher Feb 21, 2024
@bogdan-rosianu bogdan-rosianu self-requested a review February 21, 2024 08:28
@popenta popenta merged commit 56541ae into feat/next Feb 21, 2024
1 check passed
@popenta popenta deleted the use-factories-in-tests branch February 21, 2024 08:33
@andreibancioiu
Copy link
Contributor

The breaking part was recovered in #404.

@andreibancioiu andreibancioiu changed the title Breaking Change: Refactor Transaction Watcher Refactor Transaction Watcher Mar 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants